package com.eedi.framework.template.dal.mapper;

import com.eedi.framework.mybatis.core.mapper.BaseMapperX;
import com.eedi.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.eedi.framework.template.controller.sys.vo.menu.SysTemplateMenuListReq;
import com.eedi.framework.template.dal.dataobject.SysTemplateMenuDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface SysTemplateMenuMapper extends BaseMapperX<SysTemplateMenuDO> {

    default SysTemplateMenuDO selectByParentIdAndName(String parentId, String name) {
        return selectOne(SysTemplateMenuDO::getParentSysMenuId, parentId, SysTemplateMenuDO::getSysMenuName, name);
    }

    default Long selectCountByParentId(String parentId) {
        return selectCount(SysTemplateMenuDO::getParentSysMenuId, parentId);
    }


    default List<SysTemplateMenuDO> selectListByPermission(String permission) {
        return selectList(SysTemplateMenuDO::getSysMenuPermission, permission);
    }

    default List<SysTemplateMenuDO> selectList(SysTemplateMenuListReq reqVO) {
        return selectList(new LambdaQueryWrapperX<SysTemplateMenuDO>()
                .likeIfPresent(SysTemplateMenuDO::getSysMenuName, reqVO.getSysMenuName())
                .eqIfPresent(SysTemplateMenuDO::getSysMenuStatus, reqVO.getSysRoleStatus()));
    }
}
